# -*- coding: utf-8 -*-
"""
Created on Mon Feb 18 15:17:28 2013

@author: Daniel
"""
from PBDO import triangle, parameters, PBDO
#--------------Test Problem 1---------------    

import math
def test1_ob(d,x,p):
    f=1.98+4.9*x[0]+6.67*x[1]+6.98*x[2]+4.01*x[3]+1.78*x[4]+2.73*x[6]
    return f

def test1_C1(d,x,p):
    C1=14.36+(-9.9*x[1]-12.9*x[0]*x[7]+0.1107*x[2]*p[0])
    return C1
def test1_C2(d,x,p):
    C2=1.86+(2.95*x[2]+0.1792*p[0]-5.057*x[0]*x[1]-11.0*x[1]*x[7]-0.0215*x[4]*p[0]-9.98*x[6]*x[7]+22.0*x[7]*x[8])
    return C2
def test1_C3(d,x,p):
    C3=-3.02+(3.818*x[2]-4.2*x[0]*x[1]+0.0207*x[4]*p[0]+6.63*x[5]*x[8]-7.7*x[6]*x[7]+0.32*x[8]*p[0])
    return C3
def test1_C4(d,x,p):
    C4=0.059+(-0.0519*x[0]*x[1]-0.188*x[0]*x[7]-0.019*x[1]*x[6]+0.0144*x[2]*x[4]+0.0008757*x[4]*p[0]+0.08045*x[5]*x[8]+0.00139*x[7]*p[1]+0.00001575*p[0]*p[1])
    return C4
def test1_C5(d,x,p):
    C5=-0.106+(0.00817*x[4]-0.131*x[0]*x[7]-0.0704*x[0]*x[8]+0.03099*x[1]*x[5]-0.018*x[1]*x[6]+0.0208*x[2]*x[7]+0.121*x[2]*x[8]-0.00364*x[4]*x[5]+0.0007715*x[4]*p[0]-0.0005354*x[5]*p[0]+0.00121*x[7]*p[1]+0.00184*x[8]*p[0]-0.018*x[1]**2)
    return C5
def test1_C6(d,x,p):
    C6=0.42+(-0.61*x[1]-0.163*x[2]*x[7]+0.001232*x[2]*p[0]-0.166*x[6]*x[8]+0.227*x[1]**2)
    return C6
def test1_C7(d,x,p):
    C7=0.72+(-0.5*x[3]-0.19*x[1]*x[2]-0.0122*x[3]*p[0]+0.009325*x[5]*p[0]+0.000191*p[1]**2)
    return C7
def test1_C8(d,x,p):
    C8=0.68+(-0.674*x[0]*x[1]-1.95*x[1]*x[7]+0.02054*x[2]*p[0]-0.0556*x[8]*p[1]-0.000786*p[1]**2)
    return C8
def test1_C9(d,x,p):
    C9=1.35+(-0.489*x[2]*x[6]-0.843*x[4]*x[5]+0.0432*x[8]*p[0]-0.0556*x[8]*p[1]-0.000786*p[1]**2)
    return C9
def test1_C10(d,x,p):
    C10=0.16+(-0.3717*x[1]*x[3]-0.00931*x[1]*p[0]-0.484*x[2]*x[8]+0.01343*x[5]*p[0])
    return C10



params=parameters()
tri=triangle()

params.addFuzzyVar(tri.getFuzzyNumber(0.5,1.0,1.5),0.5,1.5)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.5,1.0,1.5),0.5,1.5)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.5,1.0,1.5),0.5,1.5)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.5,1.0,1.5),0.5,1.5)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.5,1.0,1.5),0.5,1.5)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.5,1.0,1.5),0.5,1.5)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.5,1.0,1.5),0.5,1.5)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.192,0.3,0.345),0.192,0.345)
tri=triangle()
params.addFuzzyVar(tri.getFuzzyNumber(0.192,0.3,0.345),0.192,0.345)
tri=triangle()
params.addFuzzyParam(tri.getFuzzyNumber(29.9999,30.,30.0001))
tri=triangle()
params.addFuzzyParam(tri.getFuzzyNumber(29.9999,30.,30.0001))

opt=PBDO(test1_ob,(test1_C1,test1_C2,test1_C4,test1_C4,test1_C5,test1_C6,test1_C7,test1_C8,test1_C9,test1_C10),
         params,dx=10**-10,alpha=0.02,nCPU=1,optimizer='SLSQP')
opt.solve()
opt.display()
#print opt.fHistory
#print opt.xHistory
#print opt.fMin
#print opt.xMin
#print opt.dMin

    
